// 收款账户明细
import { getCollectionAccountList } from '@/api/company'
import type { CollectionAccountDto, CollectionAccountReqDto } from '@/api/company/types'
import { AccountStateCnEnum, CollectionAccountStatusCnEnum, CollectionAccountTypeCnEnum, getKeyToEnum, PayModeCnEnum, ProductTypeCnEnum } from '@/const/enum'
import type { FilterDto } from '@/render/FilterRender'
import TableRender, { type TableRenderColumnTypes } from '@/render/TableRender'
import type { AnyObject } from '@/types'
import toNative from '@/utils/toNative'
import { Component } from 'vue-facing-decorator'
import DialogExport from './components/DialigExport'
import { Button } from 'ant-design-vue'

@Component
export class Withdraw extends TableRender {
    showExport = false

    filterConfig(): FilterDto {
        return {
            companyId: {
                name: '客户名称',
                element: 'select',
                optionsType: 'company'
            },
            productType: {
                name: '产品类型',
                element: 'select',
                options: getKeyToEnum(ProductTypeCnEnum)
            },
            rechargeTime: {
                name: '交易时间',
                element: 'rangePicker',
            }
        }
    }

    tableColumnConfigOld = () =>
        [
            {
                field: 'companyName',
                title: '客户名称',
                width: 200
            },
            {
                field: 'productType',
                title: '产品类型',
                formatter: ({row}) => {
                    return ProductTypeCnEnum[row.productType]
                }
            },
            {
                field: 'operateAmount',
                title: '交易金额',
                slots: {
                    default: 'price'
                }
            },
            {
                field: 'createTime',
                title: '交易时间',
                width: 160
            },
            {
                field: 'remark',
                title: '备注',
            },
            {
                field: 'status',
                title: '状态',
                formatter: ({row}) => {
                    return AccountStateCnEnum[row.status]
                },
                params: {
                    colors: {
                        0: 'black-200',
                        1: 'black-200',
                        2: 'error',
                        3: 'blue-100',
                        4: 'green',
                        5: 'yellow'
                    }
                },
                slots: {
                    default: 'status'
                }
            },
        ] as TableRenderColumnTypes<CollectionAccountDto>

    getParams() {
        const params = this.getFilters()
        params.position = 1
        params.selectType = CollectionAccountTypeCnEnum.提现
        params.startTime = params.rechargeTime?.[0]
        params.endTime = params.rechargeTime?.[1]
        delete params.rechargeTime
        return params as CollectionAccountReqDto
    }

    onLoadData(pageNum: number, pageSize: number, filters: AnyObject) {
        filters.startTime = filters.rechargeTime?.[0]
        filters.endTime = filters.rechargeTime?.[1]
        delete filters.rechargeTime
        return getCollectionAccountList({
            pageNum,
            pageSize,
            ...this.getParams()
        })
    }

    renderRightBtns() {
        return <>
            <Button onClick={() => {
                this.showExport = true
            }}>导出</Button>
        </>
    }

    render() {
        return <>
            {super.render()}
            <DialogExport v-model:show={this.showExport} params={this.getParams()} />
        </>
    }
}

export default toNative(Withdraw)
